package de.hauschild.gmltracer.gml.impl.array;

import de.hauschild.gmltracer.gml.Environment;
import de.hauschild.gmltracer.gml.TokenStack;
import de.hauschild.gmltracer.gml.impl.AbstractToken;
import de.hauschild.gmltracer.gml.impl.value.integer.IntegerToken;

/**
 * Pops a {@link ArrayToken} and pushes its length as {@link IntegerToken}.
 * 
 * @author Klaus Hauschild
 * @since 1.0.0
 */
public class ArrayLengthToken extends AbstractToken {

  @SuppressWarnings("boxing")
  @Override
  public void evaluate(final Environment environment, final TokenStack tokenStack) {
    final ArrayToken array = tokenStack.pop(ArrayToken.class);

    tokenStack.push(new IntegerToken(array.getLength()));
  }

  @Override
  public String toString() {
    return "length"; //$NON-NLS-1$
  }
}
